package mylab.starters.uuid.config.redis;

import lombok.RequiredArgsConstructor;
import mylab.starters.uuid.config.UuidAutoConfiguration;
import mylab.starters.uuid.config.UuidProperties;
import mylab.starters.uuid.impl.redis.RedisUuidTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@AutoConfigureAfter(UuidAutoConfiguration.class)
@ConditionalOnProperty(value = ReidsUuidAutoConfiguration.PREFIX, havingValue = "true")
public class ReidsUuidAutoConfiguration {

    static final public String PREFIX = UuidProperties.PREFIX + ".redis.enabled";

    final private UuidProperties properties;

    @Bean
    @ConditionalOnMissingBean
    public RedisUuidTemplate template() {
        return new RedisUuidTemplate(properties.getRedis());
    }
}
